package com.example.safelib

import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.core.view.isVisible
import androidx.navigation.NavController
import androidx.navigation.Navigation
import androidx.navigation.ui.NavigationUI
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.baselib.WaterMarkBg
import com.example.baselib.activity.BaseActivity
import com.example.baselib.activity.BaseViewModelActivity
import com.example.baselib.constants.ARConstants
import com.example.safelib.adapter.SafeAlarmAdapter
import kotlinx.android.synthetic.main.activity_safe_main.*
import kotlinx.android.synthetic.main.fragment_safe_alarm.*

// 在支持路由的页面上添加注解(必选)
// 这里的路径需要注意的是至少需要有两级，/xx/xx
@Route(path = ARConstants.APP_SAFE)
class SafeMainActivity : BaseViewModelActivity<SafeViewModel>() {
    override fun providerVMClass(): Class<SafeViewModel>? {
        return SafeViewModel::class.java
    }

    private val findNavController:NavController by lazy { Navigation.findNavController(this, R.id.safe_nav_fragment) }
    override fun layoutResId(): Int {
        return R.layout.activity_safe_main
    }

    override fun initView() {
        setToolbarMsg("安全监控")
        setToolbarColor(R.color.colorDBlue, R.color.colorWhite)
        setToolbarMenu(true, R.id.menu_safe)
        safe_bottom.itemIconTintList = null
        safe_background.background = WaterMarkBg
        NavigationUI.setupWithNavController(
            safe_bottom,
            findNavController
        )
        findNavController.addOnDestinationChangedListener { controller, destination, arguments ->
            when(destination.id){
                R.id.safeAlarmLCFragment ,R.id.safeSensorInfoFragment-> safe_bottom.visibility=View.GONE
                else ->  safe_bottom.visibility=View.VISIBLE
            }
        }
    }

    override fun initData() {
        try {
            val map:HashMap<String,String> =HashMap()
            map["unitname"]=intent.getStringExtra("unitname")
            map["unitcode"]=intent.getStringExtra("unitcode")
            viewModel.setUnitInfo(map)
        } catch (e: Exception) {

        }
    }

    override fun backOnClick() {
         onBackPressed()
    }

    override fun onBackPressed() {
        when(findNavController.currentDestination?.id){
            R.id.safeAlarmLCFragment ,R.id.safeSensorInfoFragment -> findNavController.popBackStack()
            else -> finish()
        }

    }
}
